package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.mapper.UserMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.RegionQueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.IUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {

    @Autowired
    private RegionMapper regionMapper;


    @Override
    public List<Region> selectRegionByParentId(QueryObject qo) {
        return regionMapper.selectByParentId(qo);
    }

    @Override
    public void saveOrUpdate(Region region) {
        if (region.getId()==null){
            regionMapper.insert(region);
        }else{
            regionMapper.updateByPrimaryKey(region);
        }
    }

    @Override
    public List<Region> list() {
        return regionMapper.selectAll();
    }

    @Override
    public void deleteById(Long id) {
        regionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo query(RegionQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Region> list = regionMapper.selectForList(qo);
        return new PageInfo(list);
    }
}
